package org.JWCB.system.controller.exam;

import jakarta.validation.constraints.NotNull;
import org.JWCB.common.core.controller.BaseController;
import org.JWCB.system.domain.exam.dto.ExamAddDto;
import org.JWCB.system.domain.exam.dto.ExamEditDto;
import org.JWCB.system.domain.exam.dto.ExamQueryDto;
import org.JWCB.system.domain.exam.dto.ExamQuestionAddDto;
import org.JWCB.system.domain.exam.vo.ExamDetailVo;
import org.JWCB.common.core.domain.vo.R;
import org.JWCB.common.core.domain.vo.TableDataInfo;
import org.JWCB.system.service.exam.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;


    @GetMapping("/list")
    public TableDataInfo list(@Validated ExamQueryDto examQueryDto) {
        return getTableList(examService.list(examQueryDto));
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody @Validated ExamAddDto examAddDto) {
        return examService.add(examAddDto);
    }


    @PostMapping("/question/add")
    public R<Void> addQuestion(@Validated @RequestBody ExamQuestionAddDto examQuestionAddDto) {
        return toR(examService.addQuestion(examQuestionAddDto));
    }

    @PutMapping("/question/update/order")
    public R<Void> questionUpdateOrder(@Validated @RequestBody ExamQuestionAddDto examQuestionAddDto) {
        return toR(examService.updateQuestionOrder(examQuestionAddDto));
    }

    @GetMapping("/detail")
    public R<ExamDetailVo> detail(Long examId) {
        return R.ok(examService.examDetail(examId));
    }


    @PutMapping("/edit")
    public R<Void> edit(@RequestBody @Validated ExamEditDto examEditDto) {
        return toR(examService.edit(examEditDto));
    }


    @DeleteMapping("/question/del")
    public R<Void> delQuestion(@NotNull(message = "竞赛id不能为空") Long examId, @NotNull(message = "题目id不能为空") Long questionId){
        return toR(examService.delQuestion(examId,questionId));
    }


    @DeleteMapping("/del")
    public R<Void> del(@NotNull(message = "竞赛id不能为空") Long examId) {
        return toR(examService.del(examId));
    }


    @PutMapping("/publish")
    public R<Void> publish(@NotNull(message = "examId不能为空") Long examId) {
        return toR(examService.publish(examId));
    }


    @PutMapping("/unpublish")
    public R<Void> unpublish(@NotNull(message = "examId不为空") Long examId) {
        return toR(examService.unpublish(examId));
    }
}
